import { createSlice } from '@reduxjs/toolkit'

const tabSlice = createSlice({
    name: 'tab',
    initialState: {
        isCollapse: false,
        tabList: [
            {
                path: '/',
                name: 'home',
                label: '首页'
            }
        ]
    },
    reducers: {
        collapseMenu: state => {
            state.isCollapse = !state.isCollapse
        },
        selectMenuList: (state, { payload: val }) => {
            if (val.name !== 'home') {
                // 如果已经存在的tag 就不需要添加
                const result = state.tabList.push.findIndex(item => item.name === val.name)
                if (result === -1) {
                    state.tabList.push(val)
                }
            }
        }
    }
})
 
export const { collapseMenu, selectMenuList } = tabSlice.actions
export default tabSlice.reducer
